package nancal.mp.entity.dev

import nancal.mp.entity.base.TestBase
import nbcp.base.extend.resolvePath
import nbcp.base.utils.FileUtil
import nbcp.myoql.code.generator.db.mongo.MorGenerator4Kotlin
import org.junit.jupiter.api.Test
import java.io.File


class MongoTool : TestBase() {


    /**
     * 启动时，在 -ea 后面添加： --add-opens java.base/sun.reflect.annotation=ALL-UNNAMED
     */
    @Test
    fun gen_mor() {

        var list = MorGenerator4Kotlin().generateEntity(
            "${entityPkgName}.db.mongo.entity.",
            "${ormPkgName}.db.mongo.table"
        )

        var targetEntityPathName = FileUtil.resolvePath(
            File(workPath).resolvePath("../${ormProjectName}/src/main/kotlin"),
            "${ormPkgName}.db.mongo.table.".split(".").joinToString("/")
        )
        File(targetEntityPathName).deleteRecursively();
        File(targetEntityPathName).mkdirs()


        list.forEach {
            writeToFile(FileUtil.resolvePath(targetEntityPathName, it.code), it.value);
        }
    }


}
